/**
 * 
 */
package composite;

/**
 * PatternBox: "Client" implementation.
 * <ul>
 *   <li>manipulates objects in the composition through the Component interface.</li>
 * </ul>
 * 
 * @author <a href="mailto:dirk.ehms@patternbox.com">Dirk Ehms</a>
 * @author lx
 */
public class Client {

	/** stores the Command instance of the Invoker */
	private Component root = null;

	/** 
	 * Default construtor
	 */
	public Client() {
		super();
	}

	/** 
	 * This construtor overloads the default constructor. An instance
	 * of Component is delivered as parameter.
	 */
	public Client(Component component) {
		super();
		root = component;
	}

	/** 
	 * This method shows an example how to create a simple composite hierarchy.
	 */
	public void createComposite() {
		root = new Branch();

		Branch composite = new Branch();
		Branch composite1 = new Branch();
		
		composite1.add(new Leaf());
		composite.add(new Leaf());
		composite.add(new Leaf());
		composite.add(composite1);

		
		
		root.add(composite);
		root.add(new Leaf());
	}

	/** 
	 * This method invokes the specific Component operation.
	 */
	public void useComposite() {
		root.operation();
	}
public static void main(String[] args) {
	Client client = new Client();
	client.createComposite();
	client.useComposite();
}
}
